using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Infrastructure.Redis
{
    /// <summary>
    /// Redis操作接口
    /// </summary>
    public interface IRedisHelper
    {
        /// <summary>
        /// 获取缓存值
        /// </summary>
        /// <typeparam name="T">缓存对象类型</typeparam>
        /// <param name="key">缓存键</param>
        /// <returns>缓存值</returns>
        Task<T?> GetAsync<T>(string key);
        
        /// <summary>
        /// 获取缓存值
        /// </summary>
        /// <typeparam name="T">缓存对象类型</typeparam>
        /// <param name="key">缓存键</param>
        /// <returns>缓存值</returns>
        T? Get<T>(string key);
        
        /// <summary>
        /// 获取字符串值
        /// </summary>
        /// <param name="key">缓存键</param>
        /// <returns>字符串值</returns>
        Task<string?> GetStringAsync(string key);
        
        /// <summary>
        /// 获取字符串值
        /// </summary>
        /// <param name="key">缓存键</param>
        /// <returns>字符串值</returns>
        string? GetString(string key);
        
        /// <summary>
        /// 设置缓存
        /// </summary>
        /// <typeparam name="T">缓存对象类型</typeparam>
        /// <param name="key">缓存键</param>
        /// <param name="value">缓存值</param>
        /// <param name="expiry">过期时间（可选）</param>
        /// <returns>是否设置成功</returns>
        Task<bool> SetAsync<T>(string key, T value, TimeSpan? expiry = null);
        
        /// <summary>
        /// 设置缓存
        /// </summary>
        /// <typeparam name="T">缓存对象类型</typeparam>
        /// <param name="key">缓存键</param>
        /// <param name="value">缓存值</param>
        /// <param name="expiry">过期时间（可选）</param>
        /// <returns>是否设置成功</returns>
        bool Set<T>(string key, T value, TimeSpan? expiry = null);
        
        /// <summary>
        /// 设置字符串值
        /// </summary>
        /// <param name="key">缓存键</param>
        /// <param name="value">字符串值</param>
        /// <param name="expiry">过期时间（可选）</param>
        /// <returns>是否设置成功</returns>
        Task<bool> SetStringAsync(string key, string value, TimeSpan? expiry = null);
        
        /// <summary>
        /// 设置字符串值
        /// </summary>
        /// <param name="key">缓存键</param>
        /// <param name="value">字符串值</param>
        /// <param name="expiry">过期时间（可选）</param>
        /// <returns>是否设置成功</returns>
        bool SetString(string key, string value, TimeSpan? expiry = null);
        
        /// <summary>
        /// 删除缓存
        /// </summary>
        /// <param name="key">缓存键</param>
        /// <returns>是否删除成功</returns>
        Task<bool> RemoveAsync(string key);
        
        /// <summary>
        /// 删除缓存
        /// </summary>
        /// <param name="key">缓存键</param>
        /// <returns>是否删除成功</returns>
        bool Remove(string key);
        
        /// <summary>
        /// 检查缓存是否存在
        /// </summary>
        /// <param name="key">缓存键</param>
        /// <returns>是否存在</returns>
        Task<bool> ExistsAsync(string key);
        
        /// <summary>
        /// 检查缓存是否存在
        /// </summary>
        /// <param name="key">缓存键</param>
        /// <returns>是否存在</returns>
        bool Exists(string key);
        
        /// <summary>
        /// 设置过期时间
        /// </summary>
        /// <param name="key">缓存键</param>
        /// <param name="expiry">过期时间</param>
        /// <returns>是否设置成功</returns>
        Task<bool> SetExpiryAsync(string key, TimeSpan expiry);
        
        /// <summary>
        /// 设置过期时间
        /// </summary>
        /// <param name="key">缓存键</param>
        /// <param name="expiry">过期时间</param>
        /// <returns>是否设置成功</returns>
        bool SetExpiry(string key, TimeSpan expiry);
        
        /// <summary>
        /// 哈希表获取字段值
        /// </summary>
        /// <typeparam name="T">值类型</typeparam>
        /// <param name="key">哈希表键</param>
        /// <param name="field">字段名</param>
        /// <returns>字段值</returns>
        Task<T?> HashGetAsync<T>(string key, string field);
        
        /// <summary>
        /// 哈希表获取字段值
        /// </summary>
        /// <typeparam name="T">值类型</typeparam>
        /// <param name="key">哈希表键</param>
        /// <param name="field">字段名</param>
        /// <returns>字段值</returns>
        T? HashGet<T>(string key, string field);
        
        /// <summary>
        /// 哈希表设置字段值
        /// </summary>
        /// <typeparam name="T">值类型</typeparam>
        /// <param name="key">哈希表键</param>
        /// <param name="field">字段名</param>
        /// <param name="value">字段值</param>
        /// <returns>是否设置成功</returns>
        Task<bool> HashSetAsync<T>(string key, string field, T value);
        
        /// <summary>
        /// 哈希表设置字段值
        /// </summary>
        /// <typeparam name="T">值类型</typeparam>
        /// <param name="key">哈希表键</param>
        /// <param name="field">字段名</param>
        /// <param name="value">字段值</param>
        /// <returns>是否设置成功</returns>
        bool HashSet<T>(string key, string field, T value);
        
        /// <summary>
        /// 哈希表删除字段
        /// </summary>
        /// <param name="key">哈希表键</param>
        /// <param name="field">字段名</param>
        /// <returns>是否删除成功</returns>
        Task<bool> HashDeleteAsync(string key, string field);
        
        /// <summary>
        /// 哈希表删除字段
        /// </summary>
        /// <param name="key">哈希表键</param>
        /// <param name="field">字段名</param>
        /// <returns>是否删除成功</returns>
        bool HashDelete(string key, string field);
        
        /// <summary>
        /// 哈希表检查字段是否存在
        /// </summary>
        /// <param name="key">哈希表键</param>
        /// <param name="field">字段名</param>
        /// <returns>是否存在</returns>
        Task<bool> HashExistsAsync(string key, string field);
        
        /// <summary>
        /// 哈希表检查字段是否存在
        /// </summary>
        /// <param name="key">哈希表键</param>
        /// <param name="field">字段名</param>
        /// <returns>是否存在</returns>
        bool HashExists(string key, string field);
        
        /// <summary>
        /// 获取哈希表所有字段值
        /// </summary>
        /// <typeparam name="T">值类型</typeparam>
        /// <param name="key">哈希表键</param>
        /// <returns>字段值字典</returns>
        Task<Dictionary<string, T>> HashGetAllAsync<T>(string key);
        
        /// <summary>
        /// 获取哈希表所有字段值
        /// </summary>
        /// <typeparam name="T">值类型</typeparam>
        /// <param name="key">哈希表键</param>
        /// <returns>字段值字典</returns>
        Dictionary<string, T> HashGetAll<T>(string key);
    }
} 